package com.example.projectcode.controller.Teacher;

import com.example.projectcode.model.Teacher;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping(value = "/teacher")
@Api(tags = "教师端登录注册接口")
public class LoginAndRegisterController {

    @Autowired
    private TeacherService teacherService;

    @ApiOperation("教师登录")
    @GetMapping(value = "/login/{teaUsername}/{teaPassword}")
    public Result login(@PathVariable String teaUsername,@PathVariable String teaPassword){
        Teacher teacher = new Teacher();
        teacher = teacherService.selectOneTeacher(teaUsername,teaPassword);
        if (teacher != null){
            return Result.ok(teacher).message("登录成功");
        }else {
            return Result.fail().message("账号或者密码错误");
        }
    }



    @ApiOperation("教师注册")
    @PostMapping("/register")
    public Result register(@RequestBody Teacher teacher){
        boolean result = teacherService.insertTeacher(teacher);
        if (result){
            return Result.ok(teacher).message("注册成功");
        }else {
            return Result.fail().message("注册失败");
        }
    }


}
